package cn.net.sichen.server.listener;

import cn.net.sichen.server.db.MockDB;
import cn.net.sichen.server.entity.ClientInfo;
import cn.net.sichen.server.util.HttpUtil;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.List;

public class SsoSessionListener implements HttpSessionListener {

    public void sessionDestroyed(HttpSessionEvent se) {
        HttpSession session = se.getSession();
        String token = (String) session.getAttribute("token");
        List<ClientInfo> clientInfos = MockDB.T_CLIENT_INFO.get(token);
        try {
            if (clientInfos != null && !clientInfos.isEmpty()) {
                for (ClientInfo clientInfo : clientInfos) {

                    HttpUtil.sendHttpRequest(clientInfo.getClientUrl(),clientInfo.getJsessionid());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
